15. 练习:Break、Continue

练习:截断字符串

break 语句写一个循环,用于创建刚好长 140 个字符的字符串 news_ticker 。你应该通过添加 headlines 列表中的新闻标题创建新闻提醒,在每个新闻标题之间插入空格。如果有必要的话,将最后一个新闻标题从中间截断,使 news_ticker 刚好长 140 个字符。

注意, break 同时适用于 for while 循环。使用你认为最合适的循环。考虑向代码中添加 print 语句以帮助你解决 bug。

Start Quiz:

# HINT: modify the headlines list to verify your loop works with different inputs
headlines = ["Local Bear Eaten by Man",
             "Legislature Announces New Laws",
             "Peasant Discovers Violence Inherent in System",
             "Cat Rescues Fireman Stuck in Tree",
             "Brave Knight Runs Away",
             "Papperbok Review: Totally Triffic"]

news_ticker = ""
# write your loop here


print(news_ticker)